import type { PageResp, TakerApplicationDto, ApproveTakerApplicationDto, GetTakerApplicationDto } from '@/types/api';
import request from '@/utils/request';

// 接单员申请信息类型
export interface TakerApplication {
  id: string;
  userId: string;
  tenantId: string;
  reason?: string;
  contactInfo?: string;
  status: 'pending' | 'approved' | 'rejected';
  approvedBy?: string;
  approvedTime?: string;
  rejectReason?: string;
  createTime: string;
  // 用户信息
  user?: {
    id: string;
    name: string;
    avatar?: string;
  };
  // 租户信息
  tenant?: {
    id: string;
    name: string;
  };
}

// 仪表板API
export const dashboardApi = {
  // 获取待审批的接单员申请（保持原有接口）
  getPendingApplications: async (params: { page: number; limit: number }): Promise<TakerApplicationDto[]> => {
    return await request.get('/admin/taker-applications/pending', { params });
  },

  // 获取接单员申请列表（支持状态筛选）
  getTakerApplications: async (params: { page: number; limit: number; status: string }): Promise<PageResp> => {
    return await request.get('/admin/taker-applications', { params });
  },

  // 获取申请详情 - 新增接口
  getTakerApplicationDetail: async (data: GetTakerApplicationDto): Promise<TakerApplicationDto> => {
    return await request.get(`/admin/taker-applications/${data.id}`);
  },

  // 审批接单员申请
  approveApplication: async (
    data: ApproveTakerApplicationDto
  ): Promise<{
    success: boolean;
    message: string;
  }> => {
    return await request.post('/admin/taker-applications/approve', data);
  }
};
